<template>
	<view>
		<view class="header">
			<view class="page">
				<view class="express" @click="changePage(0)" :class="pageChange==0? 'active':'' ">快递配送</view>
				<view class="toShop" @click="changePage(1)" :class="pageChange==1? 'active':'' ">到店自提</view>
			</view>
			<view class="content" @click="address_show=true" v-if="pageChange==0">
				<u-cell-group>
					<u-cell isLink>
						<view slot="title" class="u-slot-title">
							<view class="name_phone">
								<view class="name">{{defaultAddress.real_name}}</view>
								<view class="phone">{{defaultAddress.phone}}</view>
							</view>
							<view class="tag_address">
								<view class="tag" v-if="defaultAddress.is_default=='1'">[默认]</view>
								<view class="address">
									{{defaultAddress.province+defaultAddress.city+defaultAddress.district+defaultAddress.detail }}
								</view>
							</view>
						</view>
					</u-cell>
				</u-cell-group>
			</view>
			<view class="content" @click="address_show=true" v-else>
				<u-cell-group>
					<u-cell isLink>
						<view slot="title" class="u-slot-title">
							<view class="name_phone">
								<view class="name">{{defaultAddress.real_name}}</view>
								<view class="phone">{{defaultAddress.phone}}</view>
							</view>
							<view class="tag_address">
								<view class="tag" v-if="defaultAddress.is_default=='1'">[默认]</view>
								<view class="address">
									{{defaultAddress.province+defaultAddress.city+defaultAddress.district+defaultAddress.detail }}
								</view>
							</view>
						</view>
					</u-cell>
				</u-cell-group>
			</view>
			<view class="striped-divider"></view>
		</view>
		<view class="goodsInfo">
			<div class="total_count">
				共n件商品
			</div>
			<view class="goodsList">
				<view class="img">
					<image src="/static/logo.png" mode="widthFix" />
				</view>
				<view class="info">
					<view class="name">name,name,name,long,namename,name,name,long,name</view>
					<view class="attr">attr,attr,attr,attr,long,attrattr,attr,attr,attr,long,attr</view>
					<view class="price">￥10086.00</view>
				</view>
				<view class="count">x999</view>
			</view>
		</view>
		<view class="orderInfo">
			<u-cell-group>
				<u-cell title="优惠券" isLink @click="coupon_show=true">
					<text slot="value" class="u-slot-value">请选择</text>
				</u-cell>
				<u-cell title="积分抵扣">
					<view slot="value" class="u-slot-value jfdk">
						当前积分
						<text class="integral">1008611</text>
						<u-checkbox-group>
							<u-checkbox v-model="useJf" shape="circle" label=""></u-checkbox>
						</u-checkbox-group>

					</view>
				</u-cell>
				<u-cell title="开具发票" isLink @click="invoice_show=true">
					<text slot="value" class="u-slot-value">不开发票</text>
				</u-cell>
				<u-cell title="用户姓名" v-if="pageChange==1">
					<view slot="value" class="u-slot-value">
						<u--input placeholder="蔡徐坤" border="none" inputAlign="right" v-model="name_value"
							@change="change"></u--input>
					</view>
				</u-cell>
				<u-cell title="联系电话" v-if="pageChange==1">
					<view slot="value" class="u-slot-value">
						<u--input placeholder="13112124545" border="none" inputAlign="right" v-model="phone_value"
							@change="change"></u--input>
					</view>
				</u-cell>
				<u-cell>
					<view slot="title" class="u-slot-title">
						备注说明
						<u--textarea class="remarks" v-model="remarks_value" maxlength='100' autoHeight
							placeholder="填写备注信息，100字以内"></u--textarea>
					</view>
				</u-cell>
			</u-cell-group>
		</view>
		<view class="fee">
			<view class="fb">
				<view class="title">
					商品总价：
				</view>
				<view class="price">
					￥9999.99
				</view>
			</view>
			<view class="fb">
				<view class="title">
					配送运费：
				</view>
				<view class="price">
					￥25.00
				</view>
			</view>
		</view>
		<view class="total_pay">
			<view class="totalPrice">合计:
				<div class="money">
					￥1220.2
				</div>
			</view>
			<view class="pay">
				立即支付
			</view>
		</view>


		<!-- 弹出层 -->

		<u-popup :show="address_show" @close="address_show=false" closeable>
			<view class="pop_address">
				<view class="title">选择地址</view>
				<view class="ad_list">
					<view class="ad_item" @click="changeAddress(ele.id)" :class=" ele.ad_checked?'active':''"
						v-for="ele in addressList" :key="ele.id">
						<view class="icon_info">
							<u-icon name="map" size="32rpx" :color="ele.ad_checked?'#2fb6fb':'#000'"></u-icon>
							<view class="info">
								<view class="name_phone">
									<view class="name">{{ele.real_name}}</view>
									<view class="phone">{{ele.phone}}</view>
								</view>
								<view class="address">
									{{ele.province+ele.city+ele.district+ele.detail }}
								</view>
							</view>
						</view>
						<view class="checked" v-if="ele.ad_checked">
							<u-icon name="checkbox-mark" size="32rpx" color="#2fb6fb"></u-icon>
						</view>
					</view>
				</view>
				<view class="other_ad">
					选择其他地址
				</view>

			</view>
		</u-popup>
		<u-popup :show="coupon_show" @close="coupon_show=false" closeable :round="10" mode="bottom">
			<view class="pop_coupon">
				<view class="title">
					优惠券
				</view>
				<image src="http://106.52.75.114//statics/images/noCoupon.png" mode="widthFix"></image>
			</view>
		</u-popup>
		<u-popup :show="invoice_show" @close="invoice_show=false" closeable>
			<view class="pop_invoice">
				<view class="title">
					抬头选择
				</view>
				<scroll-view scroll-y="true" class="invoice_scroll">
					<u-radio-group v-model="radiovalue1" placement="column" @change="groupChange">
						<u-radio
							:customStyle="{margin: '0 30rpx 16rpx ',padding:'30rpx 20rpx','background-color': '#fff'}"
							v-for="(item, index) in radiolist1" :key="index" :label="item.name" :name="item.name"
							@change="radioChange">
							<view class="content" @click="radiovalue1=item.name">
								<view class="left">
									<view class="name_tag">
										<view class="name">{{item.name}}</view>
										<view class="default" v-if="item.is_default">默认</view>
									</view>
									<view class="info">
										联系邮箱 {{item.email}}
									</view>
									<view class="info" v-if="item.header_type=='1'">
										联系电话{{item.drawer_phone}}
									</view>
									<view class="info" v-else>
										企业税号{{item.drawer_phone}}
									</view>
								</view>
								<view class="right">
									<view class="type" :class="item.type=='2'?'unique':''">
										{{item.header_type=="1"? "个人":"企业"}}
										{{item.type=="1"? "普通":"专用"}}
									</view>
									<view class="edit" @click="edit_invoice">
										<u-icon name="edit-pen"></u-icon>
										编辑
									</view>
								</view>
							</view>
						</u-radio>
					</u-radio-group>
				</scroll-view>
				<view class="selectBtn">
					<view class="newInvoice">
						添加新的抬头
					</view>
					<view class="noUse" @click="noUseInvoice">
						不开发票
					</view>
				</view>
			</view>
		</u-popup>

	</view>
</template>

<script>
	import {
		GetDefaultAddress,
		GetAddressList,
		GetAddressDetail,
		comfirm,
	} from "@/config/api.js"

	export default {
		data() {
			return {
				pageChange: 0,
				remarks_value: '',
				name_value: '',
				phone_value: '',
				useJf: false,
				address_show: false,
				invoice_show: false,
				coupon_show: false,
				radiolist1: [{
						email: '110@112.com',
						drawer_phone: 13045678915,
						duty_number: "91440101MA5CQXQF7C",
						name: '苹果',
						header_type: "1",
						type: "1",
						is_default: false,
						disabled: false
					},
					{
						email: '110@112.com',
						drawer_phone: 13045678915,
						duty_number: "91440101MA5CQXQF7C",
						name: '香蕉',
						header_type: "2",
						type: "1",
						is_default: true,
						disabled: false
					},
					{
						email: '110@112.com',
						drawer_phone: 13045678915,
						duty_number: "91440101MA5CQXQF7C",
						name: '橙子',
						header_type: "1",
						type: "2",
						is_default: false,
						disabled: false
					}, {
						email: '110@112.com',
						drawer_phone: 13045678915,
						duty_number: "91440101MA5CQXQF7C",
						name: '榴莲',
						header_type: "2",
						type: "2",
						is_default: false,
						disabled: false
					},
					{
						email: '110@112.com',
						drawer_phone: 13045678915,
						duty_number: "91440101MA5CQXQF7C",
						name: '梨子',
						header_type: "1",
						type: "2",
						is_default: false,
						disabled: false
					}, {
						email: '110@112.com',
						drawer_phone: 13045678915,
						duty_number: "91440101MA5CQXQF7C",
						name: '坤坤',
						header_type: "2",
						type: "2",
						is_default: false,
						disabled: false
					},
					{
						email: '110@112.com',
						drawer_phone: 13045678915,
						duty_number: "91440101MA5CQXQF7C",
						name: '芒果',
						header_type: "1",
						type: "2",
						is_default: false,
						disabled: false
					}, {
						email: '110@112.com',
						drawer_phone: 13045678915,
						duty_number: "91440101MA5CQXQF7C",
						name: 'op',
						header_type: "2",
						type: "2",
						is_default: false,
						disabled: false
					}
				],
				radiovalue1: '苹果',
				defaultAddress: {},
				addressList: [],
				cartId:'',
				new:0,
			}

		},
		onLoad(option){
			console.log("op",option.cartId);
			this.cartId=option.cartId
			if(option.new){
				this.new=option.new
			}
		},
		async onShow() {
			let res = await GetDefaultAddress()
			this.defaultAddress = res.data
			res = await GetAddressList({
				params: {
					page: 1,	
					limit: 5
				}
			})
			res.data.map(
				v => {
					if (v.is_default == 1) return v.ad_checked = true
					return v.ad_checked = false
				}
			)
			this.addressList = res.data

			console.log('res', res);
		},
		methods: {
			async changeAddress(id) {
				const res = await GetAddressDetail(id)
				this.defaultAddress = res.data
				this.address_show = false
				this.addressList.forEach(v => {
					if (v.id == id) v.ad_checked = true
					else v.ad_checked = false
				})
			},

			noUseInvoice() {
				this.invoice_show = false
			},
			changePage(page) {
				this.pageChange = page
			},
			groupChange(n) {
				console.log('groupChange', n);
			},
			radioChange(n) {
				console.log('radioChange', n);
			},
			edit_invoice() {
				console.log("edit");
			}
		}
	}
</script>

<style lang="less" scoped>
	page {
		background-color: #f0f0f0;
		padding-bottom: 100rpx;
	}

	.header {
		background: linear-gradient(#2fb6fb, #f0f0f0);
		width: 100%;
		padding: 20rpx;
		box-sizing: border-box;
		height: 240rpx;

		.page {
			height: 80rpx;
			width: 100%;
			color: #32bafc;
			display: flex;
			align-items: flex-end;

			.express,
			.toShop {
				flex: 1;
				height: 60rpx;
				text-align: center;
				line-height: 60rpx;
				background-color: #bde7fd;
				position: relative;
				border-radius: 4rpx 4rpx 0 0;
			}

			.express.active,
			.toShop.active {
				background-color: #fff;
				height: 80rpx;
				line-height: 60rpx;
				width: 40%;

				&::before {
					position: absolute;
					z-index: 10;
					content: '';
				}
			}

			.express.active::before {
				border-width: 0 20rpx 80rpx 0;
				border-style: solid;
				border-color: transparent transparent #fff transparent;
				right: -20rpx;
				bottom: 0;

			}

			.toShop.active::before {
				border-width: 80rpx 20rpx 0 0;
				border-style: solid;
				border-color: transparent #fff transparent transparent;
				left: -19rpx;
				bottom: 0;
			}


		}

		.content {
			background-color: #fff;
			width: 100%;
			height: 120rpx;

			::v-deep .u-line {
				display: none;
			}

			.name_phone {
				display: flex;
				font-size: 32rpx;
				font-weight: bold;
				gap: 40rpx;
			}

			.tag_address {
				display: flex;
				font-size: 28rpx;
				gap: 20rpx;

				.tag {
					color: #2fb6fb;
				}
			}
		}

		.striped-divider {
			height: 2rpx;
			width: 100%;
			background: repeating-linear-gradient(90deg,
					#ff0000 0, #ff0000 20rpx,
					transparent 20rpx, transparent 30rpx,
					#0000ff 30rpx, #0000ff 50rpx,
					transparent 50rpx, transparent 60rpx);
		}
	}

	.goodsInfo {
		background-color: #fff;
		width: 100%;
		margin: 10rpx 0;

		.total_count {
			font-size: 32rpx;
			width: 100%;
			box-sizing: border-box;
			padding: 20rpx;
			border-bottom: 1rpx solid #f0f0f0;
		}

		.goodsList {
			width: 100%;
			padding: 20rpx;
			box-sizing: border-box;
			display: flex;
			gap: 20rpx;

			.img image {
				width: 130rpx;
				height: 130rpx;
			}

			.info {
				width: 450rpx;

				.name,
				.attr {
					display: -webkit-box;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 1;
					overflow: hidden;
					text-overflow: ellipsis;
				}

				.name {
					font-size: 32rpx;
				}

				.attr {
					font-size: 24rpx;
					color: #aaa;
				}

				.price {
					color: #fd7c74;
					font-size: 24rpx;
					margin-top: 10rpx;
				}

			}

			.count {
				width: 90rpx;
				color: #333;
				font-size: 24rpx;
				text-align: center;
				padding-top: 10rpx;
			}
		}
	}

	.orderInfo {
		background-color: #fff;

		.u-slot-value {

			color: #ccc;

			&.jfdk {

				display: flex;

				.integral {
					color: #f00;
					margin-right: 20rpx;
				}
			}
		}

		.remarks {
			background-color: #f9f9f9;
			margin: 20rpx 0;
		}
	}

	.total_pay {
		position: fixed;
		bottom: 0;
		height: 100rpx;
		width: 100%;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		box-sizing: border-box;
		padding: 10rpx 20rpx;
		align-items: center;

		.totalPrice {
			font-size: 28rpx;
			display: flex;
			height: 80rpx;
			align-items: center;

			.money {
				color: #f00;
			}
		}

		.pay {
			width: 240rpx;
			height: 70rpx;
			background-color: #2fb6fb;
			color: #fff;
			border-radius: 40rpx;
			font-size: 30rpx;
			line-height: 70rpx;
			text-align: center;
		}
	}

	.fee {
		width: 100%;
		box-sizing: border-box;
		padding: 30rpx;
		background-color: #fff;
		margin: 20rpx 0;

		.fb {
			display: flex;
			justify-content: space-between;
			align-items: center;
			height: 60rpx;

			.price {
				color: #ccc;
				font-size: 28rpx;
			}

			.title {
				font-size: 32rpx;
			}
		}
	}

	.pop_address {
		background-color: #fff;

		.title {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
		}

		.ad_list {
			width: 100%;

			.ad_item {
				width: 100%;
				height: 120rpx;
				align-items: center;
				box-sizing: border-box;
				padding: 20rpx;
				border-bottom: 1rpx solid #f0f0f0;
				display: flex;
				justify-content: space-between;

				.icon_info {
					display: flex;

					.info {
						margin: 0 20rpx;

						.name_phone {
							display: flex;
							gap: 20rpx;
							font-size: 30rpx;
							font-weight: bold;
						}

						.address {
							font-size: 24rpx;
						}
					}
				}

				&.active {
					color: #2fb6fb;
				}
			}
		}

		.other_ad {
			width: 600rpx;
			border-radius: 80rpx;
			height: 80rpx;
			background-color: #2fb6fb;
			color: #fff;
			text-align: center;
			line-height: 80rpx;

			margin: 40rpx auto;
		}
	}

	.pop_coupon {
		background-color: #fff;
		display: flex;
		flex-direction: column;
		justify-content: center;

		.title {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
		}

		image {
			width: 414rpx;
			// height: 600rpx;
			margin: 240rpx auto;
		}
	}

	.pop_invoice {
		background-color: #f0f0f0;

		.title {
			width: 100%;
			height: 100rpx;
			line-height: 100rpx;
			font-size: 32rpx;
			font-weight: bold;
			text-align: center;
		}

		.invoice_scroll {
			height: 600rpx;

			.content {
				margin-left: 10rpx;
				width: 100%;
				display: flex;
				justify-content: space-between;

				.left {
					display: flex;
					flex-direction: column;
					gap: 20rpx;

					.name_tag {
						display: flex;
						gap: 20rpx;
						align-items: center;

						.name {
							font-size: 32rpx;
							font-weight: bold;
						}

						.default {
							border: 1rpx solid #2fb6fb;
							font-size: 16rpx;
							color: #2fb6fb;
						}
					}

					.info {
						font-size: 24rpx;
						color: #aaa;
					}
				}

				.right {
					display: flex;
					flex-direction: column;
					justify-content: space-between;
					font-size: 24rpx;

					.type {
						width: 160rpx;
						height: 40rpx;
						background-color: #fcf0e0;
						color: #fcc009;
						text-align: center;
						line-height: 40rpx;

						&.unique {
							background-color: #fde9e7;
							color: #fd7c74;
						}
					}

					.edit {
						display: flex;
						justify-content: flex-end;
					}
				}
			}
		}

		.selectBtn {
			width: 100%;
			box-sizing: border-box;
			padding: 20rpx 30rpx;

			.newInvoice {
				width: 100%;
				height: 80rpx;
				background-color: #2fb6fb;
				color: #fff;
				line-height: 80rpx;
				text-align: center;
				border-radius: 80rpx;
				font-size: 32rpx;
			}

			.noUse {
				margin: 30rpx 0;
				width: 100%;
				height: 80rpx;
				border-radius: 80rpx;
				border: 1rpx solid #2fb6fb;
				color: #2fb6fb;
				line-height: 80rpx;
				border-radius: 80rpx;
				text-align: center;
			}
		}
	}
</style>